package com.kunbo.cn.controller.core.purchase;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.dto.SalesVolumeHistoryDto;
import com.kunbo.cn.entity.core.purchase.SalesVolume;
import com.kunbo.cn.service.core.purchase.SalesVolumeHistoryService;
import com.kunbo.cn.service.core.purchase.SalesVolumeService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

/**
 * 销售调量
 * @author fengze
 *
 */
@RestController
@RequestMapping("/salesVolume")
public class SalesVolumeController {

	@Autowired
	private SalesVolumeService service;
	
	@Autowired
	private SalesVolumeHistoryService volumeHistory;
	
	@RequestMapping("/save")
	public ResultBean<Boolean> save(
			@RequestParam("order_number") String order_number,
			@RequestParam("order_name") String order_name,
			@RequestParam("customer") String customer,
			@RequestParam("settlement_method") String settlement_method,
			@RequestParam("number_of_contracts") float number_of_contracts,
			@RequestParam("create_user_id") String create_user_id,
			@RequestParam("uuid") String uuid,
			@RequestParam("taskid") Integer taskid,
			@RequestParam("material")String material,
			@RequestParam("material_type")String material_type,
			@RequestParam("unit_price_of_material")Float unit_price_of_material,
			@RequestParam("contract_amount")Float contract_amount
			){
		ResultBean<Boolean>   result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result,"成功","失败",service.save(order_number, order_name, customer, settlement_method, number_of_contracts, create_user_id, uuid, taskid,material,material_type,unit_price_of_material,contract_amount));
	}

	@RequestMapping("/update")
	public ResultBean<Boolean>  update(
		@RequestParam("id") Integer id,
		@RequestParam("order_number") String order_number,
		@RequestParam("order_name") String order_name,
		@RequestParam("customer") String customer,
		@RequestParam("material_classification") String material_classification,
		@RequestParam("material") String material,
		@RequestParam("settlement_method") String settlement_method,
		@RequestParam("adjustment_amount") float adjustment_amount,
		@RequestParam("number_of_contracts") float number_of_contracts,
		@RequestParam("remarks") String remarks
		){
		ResultBean<Boolean>  result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result,"成功", "失败",service.update(id, order_number, order_name, customer, material_classification, material, settlement_method, adjustment_amount, number_of_contracts, remarks));
		
	}
	
	@RequestMapping("/sel")
	public ResultBean<SalesVolume> sel(
			@RequestParam("id") Integer id
			){
		ResultBean<SalesVolume>  result = new  ResultBean<SalesVolume>();
		return BuildBean.buildResult(result,"成功", "失败",service.sel(id));
	}
	
	@RequestMapping("/selByCondition")
	public ResultBean<List<Map<String,Object>>> selByCondition(
			@RequestParam("order_number") String order_number,
			@RequestParam("material") String material,
			@RequestParam("customer") String customer,
			@RequestParam("page") Integer page,
			@RequestParam("pageSize") Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "成功", "失败", service.selByCondition(order_number, material, customer, page, pageSize));
	}
	
	//保存调量历史
	@RequestMapping("/saveSalesVolumeHistory")
	public ResultBean<Boolean> saveSalesVolumeHistory(
			@RequestParam("uuid") String uuid,
			@RequestParam("create_user_id") String create_user_id,
			@RequestParam("taskid") Integer taskid,
			@RequestParam("order_number") String order_number,
			@RequestParam("adjustment_time") String adjustment_time,
			@RequestParam("quantity_before_adjustment") double quantity_before_adjustment,
			@RequestParam("adjusted_quantity") double adjusted_quantity,
			@RequestParam("Adjusts") String Adjusts
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result,"成功", "失败",volumeHistory.save(uuid, create_user_id, taskid, order_number, adjustment_time, quantity_before_adjustment, adjusted_quantity, Adjusts));
		
	}
	
	//根据订单号获取调量历史
	@RequestMapping ("/getSalesVolumeHistory")
	public ResultBean <List<SalesVolumeHistoryDto>> getSalesVolumeHistory(
			@RequestParam("order_number") String order_number
			){
		ResultBean<List<SalesVolumeHistoryDto>> result = new ResultBean<List<SalesVolumeHistoryDto>>();
		return BuildBean.buildResult(result, "成功", "失败",volumeHistory.get(order_number));
	}
	
	
}
